home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / python / python-1.000 / python-1 / usr / local / lib / python / shelve.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  1995-05-29  |  4.1 KB  |  45 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 1.1)
  3.  
  4. '''Manage shelves of pickled objects.
  5.  
  6. A "shelf" is a persistent, dictionary-like object.  The difference
  7. with dbm databases is that the values (not the keys!) in a shelf can
  8. be essentially arbitrary Python objects -- anything that the "pickle"
  9. module can handle.  This includes most class instances, recursive data
  10. types, and objects containing lots of shared sub-objects.  The keys
  11. are ordinary strings.
  12.  
  13. To summarize the interface (key is a string, data is an arbitrary
  14. object):
  15.  
  16. \timport shelve
  17. \td = shelve.open(filename) # open, with (g)dbm filename -- no suffix
  18.  
  19. \td[key] = data\t# store data at key (overwrites old data if
  20. \t\t\t# using an existing key)
  21. \tdata = d[key]\t# retrieve data at key (raise KeyError if no
  22. \t\t\t# such key)
  23. \tdel d[key]\t# delete data stored at key (raises KeyError
  24. \t\t\t# if no such key)
  25. \tflag = d.has_key(key)\t# true if the key exists
  26. \tlist = d.keys()\t# a list of all existing keys (slow!)
  27.  
  28. \td.close()\t# close it
  29.  
  30. Dependent on the implementation, closing a persistent dictionary may
  31. or may not be necessary to flush changes to disk.
  32. '''
  33. 'Manage shelves of pickled objects.\n\nA "shelf" is a persistent, dictionary-like object.  The difference\nwith dbm databases is that the values (not the keys!) in a shelf can\nbe essentially arbitrary Python objects -- anything that the "pickle"\nmodule can handle.  This includes most class instances, recursive data\ntypes, and objects containing lots of shared sub-objects.  The keys\nare ordinary strings.\n\nTo summarize the interface (key is a string, data is an arbitrary\nobject):\n\n\timport shelve\n\td = shelve.open(filename) # open, with (g)dbm filename -- no suffix\n\n\td[key] = data\t# store data at key (overwrites old data if\n\t\t\t# using an existing key)\n\tdata = d[key]\t# retrieve data at key (raise KeyError if no\n\t\t\t# such key)\n\tdel d[key]\t# delete data stored at key (raises KeyError\n\t\t\t# if no such key)\n\tflag = d.has_key(key)\t# true if the key exists\n\tlist = d.keys()\t# a list of all existing keys (slow!)\n\n\td.close()\t# close it\n\nDependent on the implementation, closing a persistent dictionary may\nor may not be necessary to flush changes to disk.\n'
  34. import pickle
  35. import StringIO
  36.  
  37. class Shelf:
  38. <CODE> Shelf
  39.  
  40. class DbShelf(Shelf):
  41. <CODE> DbShelf
  42.  
  43. def open():
  44. <CODE> open
  45.